#! /usr/bin/env node 
const fs = require("fs");
const path = require("path");
const chalk = require("chalk");
const argv = process.argv;
let dataFile = fs.readdirSync(path.join(__dirname+"/data"),"utf-8").map(item=>item.slice(0,-4))
let random = (max,min)=>Math.floor(Math.random()*(max-min)+1)-min;
console.log(dataFile);
if(argv[2]&&argv[2]=="animals"){
    let animalsData = fs.readFileSync(path.join(__dirname+"/data/animals.txt"),"utf-8").split("===============++++SEPERATOR++++====================");
    console.log(chalk.rgb(random(256,0),random(256,0),random(256,0)).underline(animalsData[random(animalsData.length-1,0)]));
}else if(argv[2]&&dataFile.indexOf(argv[2])!==-1){
    let animalsData = fs.readFileSync(path.join(__dirname+"/data/"+argv[2]+".txt"),"utf-8").split("%");
    console.log(chalk.rgb(random(256,0),random(256,0),random(256,0)).underline(animalsData[random(animalsData.length-1,0)]));
}else{
    console.log("命令不存在");
}